<template>
  <van-cell :title="autor.name" fit="cover" size="mini" :label="label" @click="$router.push(`/chathistory/${autor.name}`)">
    <van-image slot="icon"
               width="50"
               height="50"
               class="vant-images"
               :src="Img" round></van-image>
    <span slot="default">{{chatdate}}</span>
  </van-cell>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'ChatCell',
  components: {},
  props: {
    autor: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      Img: ''
    }
  },
  computed: {
    ...mapState(['chath']),
    label () {
      var user = this.chath.find(val => val.name === this.autor.name)
      if (user.message.length > 0) {
        return user.message[user.message.length - 1]
      }
      return '我是' + this.autor.name + '，你好呀'
    },
    chatdate () {
      var user = this.chath.find(val => val.name === this.autor.name)
      return user.date
    }
  },
  created () {
    var p = this.autor.photo
    this.Img = require('@/assets/touxiang/' + p)
  }
}
</script>

<style scoped lang="less">
  .van-image{
      margin-right:20px;
  }
</style>
